//
//  FLMHomeHeaderView.m
//  FLMSuperS
//
//  Created by xiaoyang on 16/9/19.
//  Copyright © 2016年 FaLaoMiaoNetworkTechnologyCo. All rights reserved.
//

#import "FLMHomeHeaderView.h"
#import "SDCycleScrollView.h"
#import "FLMThreeJumpView.h"

#import "FLMHomeResponseModel.h"
@interface FLMHomeHeaderView()<SDCycleScrollViewDelegate>

@property (nonatomic,strong) FLMThreeJumpView        * threeJumpView;
@property (nonatomic, strong) SDCycleScrollView      * lunboV; //轮播视图
@property (nonatomic, strong) NSArray                *lubModelArray;

@end

@implementation FLMHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self layoutUI];
        self.backgroundColor = white;
    }
    
    return self;
}

- (NSArray *)lubModelArray
{
    if (!_lubModelArray) {
        _lubModelArray = [[NSArray alloc]init];
    }
    
    return _lubModelArray;
}

- (void)layoutUI
{
    [self cycleScrollview];
    [self creatThreeJumpView];
}

+ (CGFloat)getViewHeightWithMenuArr:(NSArray *)array
{
    CGFloat bannarHeight = ScreenW * 2 / 3;
    CGFloat menuHeight = [FLMThreeJumpView getItemHeight:array];
    return bannarHeight + menuHeight;
}

//顶部轮播图
- (void)cycleScrollview{
    
    //网络图片实现
    NSArray *imagesURLStrings = @[
                                  @"1",
                                  @"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg",
                                  @"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"
                                  ];
    
    //网络加载图片轮播器
    CGRect frame = CGRectMake(0, 0, ScreenW, ScreenW*2/3);
    self.lunboV = [SDCycleScrollView cycleScrollViewWithFrame:frame delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    self.lunboV.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    
    self.lunboV.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    [self addSubview:self.lunboV];
    
    //加载延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.lunboV.imageURLStringsGroup = imagesURLStrings;
    });
    
    //     block监听点击方式
    __weak typeof (self) weakSelf = self;
    self.lunboV.clickItemOperationBlock = ^(NSInteger index) {
        NSLog(@">>>>>  %ld", (long)index);
        if (!weakSelf.lubModelArray.count) {
            return ;
        }
        FLMIndexlunboModel *lunboModel = weakSelf.lubModelArray[index];
        if (weakSelf.bannarClickBlock) {
            weakSelf.bannarClickBlock(lunboModel.jump_url);
        }
    };
    
    
}

#pragma mark --------------------
#pragma mark 第三方网页url跳转视图
- (void)creatThreeJumpView
{
    _threeJumpView = [[FLMThreeJumpView alloc]initWithFrame:CGRectMake(0, _lunboV.bottom, ScreenW, ScreenW*2/5)];
    
    __weak typeof (self) weakSelf = self;
    [_threeJumpView setImageClickBlock:^(FLMUnionsModel *model) {
        if (weakSelf.muenClickBlock) {
            weakSelf.muenClickBlock(model);
        }
    }];
    [self addSubview:_threeJumpView];
}


#pragma mark -- 设置数据
- (void)configBannarView:(NSArray *)pics menuArr:(NSArray *)menuArr
{
    //第三方网页url跳转视图配置数据
    [_threeJumpView configViewWithArray:menuArr];
    
    //轮播配置数据
    _lubModelArray = pics;
    NSMutableArray *picUrls = [[NSMutableArray alloc]init];
    for (FLMIndexlunboModel *lbModel in pics) {
        [picUrls addObject:lbModel.filename];
    }
    self.lunboV.imageURLStringsGroup = picUrls;
}

@end
